let app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },
  qq_numchage:function(e){
    if(typeof(e.detail.value)!='undefined')
    {
      var user=this.data.userInfo
      user['qq_num']=e.detail.value
      this.setData({
        userInfo:user
       })
    }
  },
  wx_numchage:function(e){
    if(typeof(e.detail.value)!='undefined')
    {
      var user=this.data.userInfo
      user['wx_num']=e.detail.value
      this.setData({
        userInfo:user
       })
    }
  },
  positionchage:function(e){
    if(typeof(e.detail.value)!='undefined')
    {
      var user=this.data.userInfo
      user['position']=e.detail.value
      this.setData({
        userInfo:user
       })
    }
  },
  user_namechage:function(e){
    if(typeof(e.detail.value)!='undefined')
    {
      var user=this.data.userInfo
      user['user_name']=e.detail.value
      this.setData({
        userInfo:user
       })
    }
  },
  phonechage:function(e){
    if(typeof(e.detail.value)!='undefined')
    {
      var user=this.data.userInfo
      user['phone']=e.detail.value
      this.setData({
        userInfo:user
       })
    }
  },
  saveinfo:function(){
    var that=this
    wx.request({
      url: app.globalData.siteroot,
      data: {
        do:'Member_editStaff',
        staff_id:wx.getStorageSync('staff_bind_id'),
        phone:that.data.userInfo.phone,
        wx_num:that.data.userInfo.wx_num,
        qq_num:that.data.userInfo.qq_num,
        position:that.data.userInfo.position,
        avatar:that.data.user_headimg,
        user_name:that.data.userInfo.user_name,
        account:that.data.userInfo.account,
        company_name:that.data.userInfo.company_name,
        user_id:wx.getStorageSync('user_id'),
        chatid:'wttskyrlhx5l8sde79xabuagworcqrvg',
        application_id:that.data.userInfo.application_id,
        rank_grade:that.data.userInfo.rank_grade,
        left_visit_message_times:that.data.userInfo.left_visit_message_times
      },
      success: function(res) {
        wx.navigateBack({
          delta:1,
          success: function() {
          }
        })
      }
    })
   
  },
  upShopLogo: function () {
    var that = this;
    wx.showActionSheet({
    itemList: ['从相册中选择', '拍照'],
    success: function (res) {
    if (!res.cancel) {
    if (res.tapIndex == 0) {
           that.chooseWxImageShop('album');
    } else if (res.tapIndex == 1) {
           that.chooseWxImageShop('camera');
        }
      }
     }
    })
  },
  chooseWxImageShop: function (type) {
    var that = this;
    wx.chooseImage({
    sizeType: ['original', 'compressed'],
    sourceType: [type],
    success: function (res) {
    that.data.user_headimg = res.tempFilePaths[0],
    that.upload_file(res.tempFilePaths[0])
    that.setData({
      user_headimg: res.tempFilePaths[0]
         })
       }
     })
    },
    upload_file: function (filePath) {
      var that = this;
      wx.uploadFile({
      url:app.globalData.siteroot+'&do=Index_uploadFile',
      filePath: filePath,
      name: 'file_upload',
      header: {
      'content-type': 'multipart/form-data'
      }, 
      formData: {
      'do':'Index_uploadFile',
      },
      success: function (res) {
      var data=JSON.parse(res.data)
      that.setData({
        user_headimg:data.info.url,
      });
      },
      fail: function (res) {}
      })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that=this
    wx.request({
      url: app.globalData.siteroot,
      data: {
        do:'Member_staffInfo',
        staff_id:wx.getStorageSync('staff_bind_id'),
      },
      success: function(res) {
        that.setData({
          userInfo:res.data.info,
          user_headimg:res.data.info.avatar
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})